/**
 * Created by kiwi on 16/12/21.
 */

import { NavigationExperimental } from 'react-native';

const {
  StateUtils: NavigationStateUtils,
} = NavigationExperimental;

const navigationTab = (state = {}, action) => {
  switch (action.type) {
    case 'NAVIGATION_PUSH':
      switch (action.tabName){
        case "tab1":
          return Object.assign({},state,{
            [action.tabName]:NavigationStateUtils.push(state[action.tabName], action.route)
          });
        case "tab2":
          return Object.assign({},state,{
            [action.tabName]:NavigationStateUtils.push(state[action.tabName], action.route)
          });
        case "tab3":
          return Object.assign({},state,{
            [action.tabName]:NavigationStateUtils.push(state[action.tabName], action.route)
          });
        default:
          return state
      }
    case 'NAVIGATION_POP':
      switch (action.tabName){
        case "tab1":
          return Object.assign({},state,{
            [action.tabName]:NavigationStateUtils.pop(state[action.tabName])
          });
        case "tab2":
          return Object.assign({},state,{
            [action.tabName]:NavigationStateUtils.pop(state[action.tabName])
          });
        case "tab3":
          return Object.assign({},state,{
            [action.tabName]:NavigationStateUtils.pop(state[action.tabName])
          });
        default:
          return state
      }

    default:
      return state
  }
};

export default navigationTab

